Class Album


  • public class Album
    extends Release
    This class represents an album as a concrete release of a specific artist.
    An album has a list of tracks, which, in this class, is implemented as a (singly) linked lists of tracks.
    Since:
    ExerciseSheet04
    Version:
    1
    Author:
    Jonas Altrock (ew20b126@technikum-wien.at)
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  Album.TrackListItem
      A single item of a linked list of tracks.
      A single list item consists of the primary data, in our case a track, and a reference to its successor, which is another list item.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Album.TrackListItem trackListHead
      The tracks of this album.
      More specifically this is the head of the linked list of tracks of this album.
    • Constructor Summary

      Constructors 
      Constructor Description
      Album()
      Creates a default Album.
      A default album is a default release with an empty track list.
      Album​(java.lang.String title, Artist artist, int year)
      Create an album with a specific title of a specific artist in a specific year.
      Album​(Album orig)
      Creates a copy of an album.
      All release parts of this album are copied as described in the release copy constructor.
    • Field Detail

      • trackListHead

        private Album.TrackListItem trackListHead
        The tracks of this album.
        More specifically this is the head of the linked list of tracks of this album.
    • Constructor Detail

      • Album

        public Album()
        Creates a default Album.
        A default album is a default release with an empty track list.
      • Album

        public Album​(Album orig)
        Creates a copy of an album.
        All release parts of this album are copied as described in the release copy constructor.

        The track list of this album contains (references to) the same tracks as the original, meaning tracks are not deeply copied.

        Parameters:
        orig - the album to copy
      • Album

        public Album​(java.lang.String title,
                     Artist artist,
                     int year)
        Create an album with a specific title of a specific artist in a specific year.
        Parameters:
        title - the title of the new album
        artist - the artist of the new album
        year - the year of the new album
    • Method Detail

      • addTrack

        public boolean addTrack​(Track t)
        Adds a track to the list of tracks.
        Tracks are added to the end of the list.

        Null tracks are not accepted. The method returns whether the list was modified. true means success (track was added) false means no success (track was NOT added).

        Parameters:
        t - the track to add
        Returns:
        whether the list was modified (added successfully) or not
      • removeTrack

        public Track removeTrack​(int n)
        Removes a track from the track from the list of tracks.

        Removes and returns the track at position n from the list of tracks. Element numbering starts at 0, such that in a list containing a single element the position of that element is 0 (zero). If the requested element does not exist in the list null is returned.

        Parameters:
        n - the (zero-based) position of the track to be removed.
        Returns:
        the removed track or null
      • nrTracks

        public int nrTracks()
        Gets the number of tracks on this album.
        Returns:
        the number of tracks
      • getTracks

        public Track[] getTracks()
        Gets the tracks of this album.

        This method creates an array containing all tracks of this album preserving their current order. If the album has no tracks, an array of size zero is returned. The tracks in the returned array are NOT (deep) copies of the tracks currently maintained by this album, meaning that the caller can modify the tracks of this album, however modification of their ordering in the list is not possible from outside.

        Returns:
        the tracks of this album in order
      • totalTime

        public int totalTime()
        Gets the total running time of this album.

        The running time is the sum of the running times of all tracks in this album. The time is returned in seconds.

        Specified by:
        totalTime in class Release
        Returns:
        the total running time in seconds.
      • toString

        public java.lang.String toString()
        Gets a String representation of this album.

        The String representation of an album adds the titles of all tracks to the release String representation. The list of track names is enclosed by opening and closing brackets ([,]). Track titles are also enclosed by opening and closing brackets.

        Overrides:
        toString in class Release
        Returns:
        the string representation